import java.util.Scanner;
import java.util.Stack;

/**
 * 矩阵乘法计算量估算
 * A是一个50×10的矩阵，B是10×20的矩阵，C是20×5的矩阵
 * 计算A*B*C有两种顺序：((AB)C)或者(A(BC))，前者需要计算15000次乘法，后者只需要3500次。
 * 编写程序计算不同的计算顺序需要进行的乘法次数。
 */
public class HJ70 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        while (scanner.hasNext()){
            int n = scanner.nextInt();
            int[][] m1 = new int[n][2];
            for (int i = 0; i < n; i++) {
                m1[i][0] = scanner.nextInt();
                m1[i][1] = scanner.nextInt();
            }

            String str = scanner.next();
            Stack<Integer> stack = new Stack<>();
            int j = n-1;
            int res = 0;
            for (int i = str.length()-1; i >=0 ; i--) {
                char c = str.charAt(i);
                if(c>='A' && c<='Z'){
                    stack.push(m1[j][1]);
                    stack.push(m1[j][0]);
                    j--;
                }

                if(c == '('){
                    int x0 = stack.pop();
                    int y0 = stack.pop();
                    int x1 = stack.pop();
                    int y1 = stack.pop();
                    res+=x0*y0*y1;

                    stack.push(y1);
                    stack.push(x0);
                }
            }
            System.out.println(res);
        }
    }
}
